Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update except usings #354

Merged
merged 1 commit into from
Jul 10, 2024
Merged

update except usings #354

merged 1 commit into from
Jul 10, 2024

Conversation

NMSAzulX
Copy link
Collaborator

@NMSAzulX NMSAzulX commented Jul 9, 2024

Summary by CodeRabbit

  • New Features

    • Introduced WithSmartBuilder and WithoutUsings methods for enhanced method configuration.
    • Added WithSmartMethodBuilder and WithoutUsings methods to streamline method builder creation.
  • Improvements

    • Enhanced handling of using directives with the new AppendExceptUsings method.
    • Improved management of excluded namespaces in using statements.
  • Refactor

    • Renamed internal fields and updated methods for better code clarity and maintenance.
  • Bug Fixes

    • Corrected logic in WithExceptUsing to ensure proper usage exclusion in caches.

Copy link

coderabbitai bot commented Jul 9, 2024

Walkthrough

This update focuses on enhancing and refining the NatashaSlimMethodBuilder class to support smarter method creation and better handling of usings exclusions. Changes include renaming fields, adding new methods for specific configurations, and updating logic related to private access and usings. Additionally, associated classes in the Natasha project have been updated to accommodate these new methods and features.

Changes

Files & Groups Change Summaries
Natasha.CSharp.Extension.MethodCreator/NatashaSlimMethodBuilder.cs Renamed fields, added configuration methods, updated logic for private access/usings.
Natasha.CSharp.Extension.MethodCreator/StringExtension.cs Added WithSmartMethodBuilder and WithoutUsings methods to the public interface.
Natasha.CSharp.Compiler/CompileUnit/AssemblyCSharpBuilder.Syntax.cs Updated Add method to handle UsingLoadBehavior with and without ExceptUsings.
Natasha.CSharp.Compiler/CompileUnit/AssemblyCSharpBuilder.Usings.cs Added functionality to manage excluded namespaces for usings.
Natasha.CSharp.Compiler/Component/Cache/NatashaUsingCache.cs Renamed WithExpectedUsing to WithExceptUsing, adjusted logic for cache updates.
Natasha.CSharp.Compiler/Extension/NatashaStringExtension.cs Modified method call to use WithExceptUsing instead of WithExpectedUsing.

Sequence Diagrams

sequenceDiagram
    participant User
    participant NatashaSlimMethodBuilder
    participant AssemblyCSharpBuilder
    participant NatashaUsingCache

    User->>NatashaSlimMethodBuilder: Call WithSmartBuilder()
    NatashaSlimMethodBuilder->>AssemblyCSharpBuilder: Configure builder

    User->>NatashaSlimMethodBuilder: Call WithoutUsings()
    NatashaSlimMethodBuilder->>AssemblyCSharpBuilder: AppendExceptUsings()

    User->>AssemblyCSharpBuilder: Add script with UsingLoadBehavior
    AssemblyCSharpBuilder->>AssemblyCSharpBuilder: Check ExceptUsings
    AssemblyCSharpBuilder->>NatashaUsingCache: Update cache logic
Loading

Poem

In the world of code, where methods grow,
Smarter builders now bestow,
Exclude the usings, stay refined,
Synced fields and logic intertwined.
From script to cache, a smoother flow,
Natasha’s magic now on show! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@NMSAzulX NMSAzulX added the pr_src 此次提交包含 [源码工程] 相关的改动. label Jul 9, 2024
@NMSAzulX
Copy link
Collaborator Author

NMSAzulX commented Jul 9, 2024

@coderabbitai review

Copy link

coderabbitai bot commented Jul 9, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@NMSAzulX
Copy link
Collaborator Author

NMSAzulX commented Jul 9, 2024

未检测到合适的 ISSUE 推荐给您。感谢您的反馈!

该条自动推荐信息来自于 nms-bot.

Copy link

github-actions bot commented Jul 9, 2024

UT Test - Ubuntu

1 tests   1 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 9c465d9.

Copy link

github-actions bot commented Jul 9, 2024

UT Test - Windows

1 tests   1 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 9c465d9.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e59011e and 9c465d9.

Files selected for processing (6)
  • src/Natasha.CSharp/Extension/Natasha.CSharp.Extension.MethodCreator/NatashaSlimMethodBuilder.cs (4 hunks)
  • src/Natasha.CSharp/Extension/Natasha.CSharp.Extension.MethodCreator/StringExtension.cs (1 hunks)
  • src/Natasha.CSharp/Natasha.CSharp.Compiler/CompileUnit/AssemblyCSharpBuilder.Syntax.cs (1 hunks)
  • src/Natasha.CSharp/Natasha.CSharp.Compiler/CompileUnit/AssemblyCSharpBuilder.Usings.cs (1 hunks)
  • src/Natasha.CSharp/Natasha.CSharp.Compiler/Component/Cache/NatashaUsingCache.cs (2 hunks)
  • src/Natasha.CSharp/Natasha.CSharp.Compiler/Extension/NatashaStringExtension.cs (1 hunks)
Additional comments not posted (15)
src/Natasha.CSharp/Natasha.CSharp.Compiler/CompileUnit/AssemblyCSharpBuilder.Usings.cs (1)

17-24: LGTM!

The method AppendExceptUsings correctly adds the provided usings to the ExceptUsings set if usings is not null and not empty.

src/Natasha.CSharp/Extension/Natasha.CSharp.Extension.MethodCreator/StringExtension.cs (2)

30-35: LGTM!

The method WithSmartMethodBuilder correctly creates a NatashaSlimMethodBuilder instance and configures it with WithSmartBuilder.


37-43: LGTM!

The method WithoutUsings correctly creates a NatashaSlimMethodBuilder instance, configures it with WithSmartBuilder, and then calls WithoutUsings with the provided usings.

src/Natasha.CSharp/Natasha.CSharp.Compiler/Extension/NatashaStringExtension.cs (1)

48-49: LGTM!

The method WithAllUsingCode correctly uses WithExceptUsing from NatashaLoadContext.DefaultContext.UsingRecorder to exclude specified usings.

src/Natasha.CSharp/Extension/Natasha.CSharp.Extension.MethodCreator/NatashaSlimMethodBuilder.cs (7)

10-10: LGTM!

The private field _exceptUsings is correctly declared as a nullable HashSet<string>.


11-11: LGTM!

The private field _privateObjects is correctly declared as a nullable object[].


22-23: LGTM!

The method WithPrivateAccess correctly uses _privateObjects instead of PrivateObjects.


43-48: LGTM!

The method WithSmartBuilder correctly configures the builder with UseRandomLoadContext and UseSmartMode.


55-59: LGTM!

The method WithoutUsings correctly calls AppendExceptUsings on the builder with the provided usings.


Line range hint 93-97:
LGTM!

The method WithMetadata correctly uses _privateObjects instead of PrivateObjects.


109-112: LGTM!

The method ToDelegate correctly uses _privateObjects for private access handling.

src/Natasha.CSharp/Natasha.CSharp.Compiler/Component/Cache/NatashaUsingCache.cs (2)

Line range hint 202-216:
LGTM! Verify correctness of WithExceptUsing(HashSet<string> exceptUsings).

The method implementation looks correct. Ensure that it works as expected in various scenarios.


216-218: LGTM! Verify performance of WithExceptUsing(IEnumerable<string> exceptUsings).

The method implementation looks correct. Ensure that the conversion to HashSet<string> does not introduce performance issues.

src/Natasha.CSharp/Natasha.CSharp.Compiler/CompileUnit/AssemblyCSharpBuilder.Syntax.cs (2)

223-303: LGTM! Verify correctness of Add(string script, UsingLoadBehavior usingLoadBehavior, Encoding? encoding = null, string filePath = "").

The method implementation looks correct. Ensure that it handles all UsingLoadBehavior cases as expected.


310-379: LGTM! Verify correctness of Add(CompilationUnitSyntax root, UsingLoadBehavior usingLoadBehavior, Encoding? encoding = null, string filePath = "").

The method implementation looks correct. Ensure that it handles all UsingLoadBehavior cases as expected.

/// </summary>
public sealed partial class AssemblyCSharpBuilder
{
public readonly HashSet<string> ExceptUsings = [];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the initialization syntax for ExceptUsings.

The initialization syntax for an empty HashSet<string> is incorrect. It should be initialized using new HashSet<string>().

-    public readonly HashSet<string> ExceptUsings = [];
+    public readonly HashSet<string> ExceptUsings = new HashSet<string>();
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public readonly HashSet<string> ExceptUsings = [];
public readonly HashSet<string> ExceptUsings = new HashSet<string>();

@NMSAzulX NMSAzulX merged commit 85aa30d into dev.next Jul 10, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr_src 此次提交包含 [源码工程] 相关的改动.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant